<?php

namespace api\controllers;

use api\components\BaseController;
use common\helpers\commonApi;
use common\models\CollectionInfo;
use common\models\System;
use common\models\Withdrawal;
use Yii;

/**
 * 提现
 */
class WithdrawalController extends BaseController
{
    /**
     * 申请提现
     * @return array|mixed
     */
    public function actionApply()
    {
        $post = Yii::$app->request->post();
        $model = new Withdrawal();
        return $model->apply(self::$userid,$post);
    }

    /**
     * 提现记录
     * @return array
     */
    public function actionList()
    {
        $get = Yii::$app->request->get();
        $page = $get['page']??1;
        $status = $get['status']??'';
        $fund_type = $get['fund_type']??'';
        $where = [];
        if ($status!==''){
            $where['review_status'] = $status;
        }
        if ($fund_type!==''){
            $where['fund_type'] = $fund_type;
        }
        $model = new Withdrawal();
        return $model->getList(self::$userid,$where,$page);
    }

    /**
     * 设置收款信息
     * @return array
     */
    public function actionSetCollection()
    {
        $post = Yii::$app->request->post();
        $model = new CollectionInfo();
        return $model->edit(self::$userid,$post);
    }

    /**
     * 获取收款信息
     * @return array
     */
    public function actionGetCollection()
    {
        $model = CollectionInfo::findOne(['userid'=>self::$userid]);
        $data = [
            'is_set'=>0,
            'username'=>'',
            'wechat_number'=>'',
            'phone'=>'',
            'collection_code'=>'',
        ];
        if ($model){
            $data['username'] = $model->username;
            $data['wechat_number'] = $model->wechat_number;
            $data['phone'] = $model->phone;
            $data['collection_code'] = commonApi::getDomain($model->collection_code);
            $data['is_set'] = 1;
        }
        return commonApi::message('ok',true,$data);
    }
}